package com.ruoyi.web.controller.cms;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.cms.domain.CmsContent;
import com.ruoyi.cms.service.ICmsContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 园区信息Controller
 * 
 * @author hct
 * @date 2022-01-22
 */
@RestController
@RequestMapping("/cms/park/content")
public class CmsContentController extends BaseController
{
    @Autowired
    private ICmsContentService cmsContentService;

    /**
     * 查询园区信息列表
     */
    @PreAuthorize("@ss.hasPermi('cms:park:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmsContent cmsContent)
    {
        startPage();
        List<CmsContent> list = cmsContentService.selectCmsContentList(cmsContent);
        return getDataTable(list);
    }

    /**
     * 导出园区信息列表
     */
    @PreAuthorize("@ss.hasPermi('cms:park:export')")
    @Log(title = "园区信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmsContent cmsContent)
    {
        List<CmsContent> list = cmsContentService.selectCmsContentList(cmsContent);
        ExcelUtil<CmsContent> util = new ExcelUtil<CmsContent>(CmsContent.class);
        util.exportExcel(response, list, "园区信息数据");
    }

    /**
     * 获取园区信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('cms:park:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(cmsContentService.selectCmsContentById(id));
    }

    /**
     * 新增园区信息
     */
    @PreAuthorize("@ss.hasPermi('cms:park:add')")
    @Log(title = "园区信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmsContent cmsContent)
    {
        return toAjax(cmsContentService.insertCmsContent(cmsContent));
    }

    /**
     * 修改园区信息
     */
    @PreAuthorize("@ss.hasPermi('cms:park:edit')")
    @Log(title = "园区信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmsContent cmsContent)
    {
        return toAjax(cmsContentService.updateCmsContent(cmsContent));
    }

    /**
     * 删除园区信息
     */
    @PreAuthorize("@ss.hasPermi('cms:park:remove')")
    @Log(title = "园区信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cmsContentService.deleteCmsContentByIds(ids));
    }

    /**
     * 上架下架信息
     */
    @PreAuthorize("@ss.hasPermi('cms:park:update')")
    @Log(title = "园区信息", businessType = BusinessType.UPDATE)
    @PutMapping("/changMarktable")
    public AjaxResult changMarktable(Long id,Integer markTable)
    {
        CmsContent cmsContent=new CmsContent();
        cmsContent.setId(id);
        cmsContent.setIsMarketable(markTable);
        return toAjax(cmsContentService.updateCmsContent(cmsContent));
    }

}
